from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.conf import settings
if settings.DATABASE_TYPE == 'mysql':
    from tanxi.models.mysql.mysql_user_model import UserModel, UserManager 
    from tanxi.models.mysql.mysql_article_model import ArticleModel
        
elif settings.DATABASE_TYPE == 'sqlite':
    from tanxi.models.sqlite.sqlite_user_model import SqliteUserModel as UserModel
    from tanxi.models.sqlite.sqlite_user_model import SqliteUserManager as UserManager
    from tanxi.models.sqlite.sqlite_article_model import SqliteArticleModel as ArticleModel
else:
    raise ValueError("Unsupported database type specified in settings.")

class CustomUserAdmin(UserAdmin):
    # 列表页显示的字段
    list_display = ('username', 'name', 'is_manager')  # 移除 is_active

    # 搜索字段
    search_fields = ('username', 'name')

    # 过滤器
    list_filter = ('is_manager',)  # 移除 is_active

    # 编辑页字段分组
    fieldsets = (
        (None, {'fields': ('username', 'password')}),
        ('个人信息', {'fields': ('name',)}),
        ('权限', {'fields': ('is_manager', 'groups', 'user_permissions')}),  # 移除 is_active
    )

    # 添加用户页字段分组
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('username', 'name', 'password1', 'password2'),
        }),
    )

# 注册 UserModel 并应用 CustomUserAdmin
admin.site.register(UserModel, CustomUserAdmin)